package com.kaifamiao.high.thread;

/**
 * @author lucien-ma
 * @date 2021/9/28
 * @apiNote
 */
public class Demo01 {
    public static void main(String[] args) throws InterruptedException {
        MyThread threadA = new MyThread("线程A");
        MyThread threadB = new MyThread("线程B");
        threadA.start();
        threadB.start();
        for (int i = 0; i < 100; i++) {
            if (Thread.currentThread().isAlive()) {
                System.out.print("活的：");
            }
            System.out.println(Thread.currentThread().getName()+i+"-------");
        }
        threadA.setPriority(10);
        System.err.println(threadA.getPriority());
        System.err.println(threadB.getPriority());
        System.err.println(Thread.currentThread().getPriority());
        System.err.println(threadB.isInterrupted());
        System.err.println("main的线程状态"+Thread.currentThread().getState());
        Thread.currentThread().sleep(2000);
        System.err.println("main的线程状态"+Thread.currentThread().getState());
        System.err.println(threadB.getName()+"的状态:"+ threadB.getState());
        System.out.println(threadA.isAlive());
    }

}

class MyThread extends Thread{

    public MyThread(){}

    public MyThread(String name) {
        super(name);
    }

    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            if (isAlive()) {
                System.out.print("活的：");
            }
            System.out.println(getName()+i+"++++++");
        }
    }
}
